package com.wyj.controller;

import com.wyj.mapper.YlrcRoleAuthoritiesMapper;
import com.wyj.pojo.YlrcRoleAuthorities;
import com.wyj.service.impl.YlrcRoleAuthoritiesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：wyj
 * @description：TODO
 * @date ：2022/11/19 4:14 下午
 */
@RestController
@RequestMapping("/roleAndMenu")
public class RoleAndMenuController {

    @Autowired
    YlrcRoleAuthoritiesServiceImpl ylrcRoleAuthoritiesServiceImpl;

    //增加一个角色的权限
    @PostMapping
    public String addRoleAndMenu(@ModelAttribute("ylrcRoleAuthorities") YlrcRoleAuthorities ylrcRoleAuthorities) {
        try {
           int result =  ylrcRoleAuthoritiesServiceImpl.addRoleAndMenu(ylrcRoleAuthorities);
           if (result > 0) return "增加角色权限成功";
        } catch (Exception e) {
            new RuntimeException(e);
        }
        return "增加角色权限失败";
    }

    //删除一个角色的权限
    @DeleteMapping
    public String deleteRoleAndMenu(@ModelAttribute("ylrcRoleAuthorities") YlrcRoleAuthorities ylrcRoleAuthorities) {
        try {
            int i = ylrcRoleAuthoritiesServiceImpl.deleteAndMenu(ylrcRoleAuthorities);
            if (i >=0 ) return "删除角色权限成功";
        } catch (Exception e) {
            new RuntimeException(e);
        }
        return "删除角色权限失败";
    }


}
